package com.opentd.graphics;

import java.awt.Graphics;
import java.util.Vector;

import com.opentd.game.Game;
import com.opentd.game.Player;
import com.opentd.game.maps.Map;
import com.opentd.npc.Wave;

public class Level implements Drawable{

	public String title;
	public int health;
	public int money;
	public Vector<Wave> waves;
	public Map map;
	public Player player;
	
	public int startMoney;
	public Vector<Wave> prevWaves;
	
	public boolean won = false;
	
	private boolean isFinished = false;
	public int currentWave = 0;
	
	
	public Level(String title, int health, int money, Vector<Wave> waves, Map map){
		this.title = title;
		this.health = health;
		this.money = money;
		startMoney = money;
		this.waves = (Vector<Wave>) waves.clone();
		prevWaves = waves;
		this.map = map;
		player = new Player(health);
	}
	
	public void logicLoop(){
		if(waves.elementAt(currentWave).isFinished){
			nextWave();
		}
		if(currentWave == waves.size()){
			if(player.health > 0){
				won = true;
				isFinished = true;
			}
		}
		waves.elementAt(currentWave).logic();
		player.logic();
	}
	
	private void nextWave() {
		currentWave++;
	}

	@Override
	public void draw(Graphics g) {
		//Draw map
		map.draw(g);
		//Draw wave of enemies
		waves.elementAt(currentWave).draw(g);
		player.draw(g);
		
	}
	
	public void printInfo(){
		System.out.println("Title: " + title);
		System.out.println("Health: " + health);
		System.out.println("Money: " + money);
		System.out.println("Number of Waves: " + waves.size());
		System.out.println("Map Size: x = " + map.width + ", y = " + map.height);
		map.print();
	}

	public void reset() {
		
	}
	
}
